<admintpl file="header1" />
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li class="active"><a href="{:U('NewsRoll/index')}">滚动列表</a></li>
			<li><a href="{:U('NewsRoll/add')}">新增滚动</a></li>
		</ul>
		<form  action="{:U('NewsRoll/edit_post')}" method="post" class="form-horizontal js-ajax-forms" enctype="multipart/form-data">
			<div class="control-group">
				<label class="control-label">滚动标题</label>
				<div class="controls">
					<input type="text" name="name" value="{$model.name}" placeholder="输入标题">
					<span class="form-required">*</span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">图片</label>
				<div class="controls">
					<input type="hidden" name="news_img" id="thumb" value="">
					<a href="javascript:void(0);" onclick="flashupload('thumb_images', '图片上传','thumb',thumb_images,'10,jpg|jpeg|gif|png|bmp,1,,,1','','','');return false;">
					  <img src="{$model.news_img}" id="thumb_preview"
					  width="135" style="cursor: hand" />
					</a>
					<input type="button" class="btn btn-small" onclick="$('#thumb_preview').attr('src','__TMPL__Public/assets/images/default-thumbnail.png');$('#thumb').val('');return false;"
					value="取消图片">
				</div>
			</div>
			<div class="control-group" id="news_table" style="display:block;">
				<label class="control-label">关联的新闻</label>
				<div class="controls">
					<table class="table table-hover table-bordered table-list">
						<thead>
							<tr>
								<th>选择</th>
								<th width="50">ID</th>
								<th>新闻标题</th>
								<th>新闻作者</th>
								<th>新闻类型</th>
							</tr>
						</thead>
						<tbody>
							<foreach name="news" item="vo">
								<tr>
									<td>										
										<input type="radio" value="{$vo.id}" name="news_id"/>
									</td>
									<td>{$vo.id}</td>
									<td>{$vo.name}</td>
									<td>{$vo.news_author}</td>
									<td>{$newsType[$vo[news_type_id]]}</td>
								</tr>
							</foreach>
						</tbody>
					</table>
					<div class="pagination">{$Page}</div>
				</div>
			</div>
			<div class="form-actions">
				<input type="hidden" value="{$model.id}" name="id" />
				<button class="btn btn-primary js-ajax-submit" type="submit">{:L('SAVE')}</button>
				<a class="btn" href="{:U('NewsRoll/index')}">{:L('BACK')}</a>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
	<script type="text/javascript">
		//编辑器路径定义
		var editorURL = GV.DIMAUB;
	</script>
	<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
	<script type="text/javascript">
		$(function() {
			$("#dropzone").dropzone({
			        url: "http://localhost/index.php?g=Asset&m=Ueditor&a=upload",
			        maxFiles: 10,
			        maxFilesize: 512,
			        addRemoveLinks:false,
			        acceptedFiles: "image/*,application/pdf,.psd,.obj,.css"
			    });
			$("#dropzone").on("complete", function(file) {
					  myDropzone.removeFile(file);
			});
			$(".js-ajax-close-btn").on('click', function(e) {
				e.preventDefault();
				Wind.use("artDialog", function() {
					art.dialog({
						id : "question",
						icon : "question",
						fixed : true,
						lock : true,
						background : "#CCCCCC",
						opacity : 0,
						content : "您确定需要关闭当前页面嘛？",
						ok : function() {
							setCookie("refersh_time", 1);
							window.close();
							return true;
						}
					});
				});
			});
			/////---------------------
			Wind.use('validate','ajaxForm','artDialog',function() {
				//编辑器
				editorcontent = new baidu.editor.ui.Editor();
				editorcontent.render('content');
				try {
					editorcontent.sync();
				} catch (err) {}
				//增加编辑器验证规则
				jQuery.validator.addMethod('editorcontent',function() {
					try {
						editorcontent.sync();
					} catch (err) {}
					return editorcontent.hasContents();
				});
				
				var form = $('form.js-ajax-forms');
				//ie处理placeholder提交问题
				if ($.browser.msie) {
					form.find('[placeholder]').each(function() {
						var input = $(this);
						if (input.val() == input
								.attr('placeholder')) {
							input.val('');
						}
					});
				}
				//表单验证开始
				form.validate({
					//是否在获取焦点时验证
					onfocusout : false,
					//是否在敲击键盘时验证
					onkeyup : false,
					//当鼠标掉级时验证
					onclick : false,
					//验证错误
					showErrors : function(errorMap,errorArr) {
						//errorMap {'name':'错误信息'}
						//errorArr [{'message':'错误信息',element:({})}]
						try {
							$(errorArr[0].element).focus();
							art.dialog({
								id : 'error',
								icon : 'error',
								lock : true,
								fixed : true,
								background : "#CCCCCC",
								opacity : 0,
								content : errorArr[0].message,
								cancelVal : '确定',
								cancel : function() {
									$(errorArr[0].element).focus();
								}
							});
						} catch (err) {}
					},
					//验证规则
					rules : {
						'name' : {required :true},
						'news_author' : {required : true},
						'news_body' : {editorcontent : true},
						'news_id' : {required :true}
					},
					//验证未通过提示消息
					messages : {
						'name' : {required : '标题不能为空'},
						'news_author' : {required : '作者不能为空'},
						'news_body' : {editorcontent : '内容不能为空'},
						'news_id' : {required :'请选择关联的新闻'}
					},
					//给未通过验证的元素加效果,闪烁等
					highlight : false,
					//是否在获取焦点时验证
					onfocusout : false,
					//验证通过，提交表单
					submitHandler : function(forms) {
						$(forms).ajaxSubmit({
							url : form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
							dataType : 'json',
							beforeSubmit : function(arr,$form,options) {
	
							},
							success : function(data,statusText,xhr,$form) {
								if (data.status) {
									setCookie("refersh_time",1);
									//添加成功
									Wind.use("artDialog",function() {
										art.dialog({
											id : "succeed",
											icon : "succeed",
											fixed : true,
											lock : true,
											background : "#CCCCCC",
											opacity : 0,
											content : data.info,
											button : [
											{
												name : '继续修改？',
												callback : function() {
													reloadPage(window);
													return true;
												},
												focus : true
											},
											{
												name : '返回列表',
												callback : function() {
													location.href = "{:U('NewsRoll/index')}";
													return true;
												}
											}
											]
										});
									});
								} else {
									alert(data.info);
								}
							}
						});
					}
				});
			});
		////-------------------------
		});
	</script>
</body>
</html>